<template>
	<!--修改和删除抬头-->
	<view class="content">
		<view class="details-from">
			<form>
				<view class="uni-details-list">
					<view class="title">默认抬头:</view>
					<view><switch name="switch" class="swiths" :checked="flag" @change="setDefault" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">名称</view>
					<view class="uni-input-01"><input name="input" placeholder="请输入名称" v-model="riseListPro.name" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">税号:</view>
					<view class="uni-input-01"><input name="input" placeholder="非必填" v-model="riseListPro.taxNo" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">企业地址:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.address" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">企业电话:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.phone" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">开户银行:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.bankAccNo" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">开户账号:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.bankNm" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">邮箱:</view>
					<view class="uni-input-02"><input name="input" placeholder="必填" v-model="riseListPro.email" /></view>
				</view>

				<view class="ad-button">
					<button form-type="submit" @tap="keyword" class="button">修改</button>
					<button type="warn" @click="delect" class="button">删除</button>
				</view>
			</form>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			riseListPro: {
				name: '',
				taxNo: '',
				address: '',
				phone: '',
				bankNm: '',
				bankAccNo: '',
				email: '',
				defaultFlag: ''
			},
			flag: ''
		};
	},
	onLoad(options) {
		console.log(options.id);
		this.detail(options.id);
	},
	methods: {
		//订单详情
		detail(id) {
			var me = this;
			console.log(id);
			uni.request({
				url: me.$ServerUrl + '/invoice/api/header/getInviceHeaderById', //通过ID获取发票详情
				data: {
					id: id
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded' // 默认值JSON格式
				},
				method: 'GET',
				success(res) {
					console.log(res);
					console.log('----cffffffcy--');
					console.log(id);
					console.log('------');
					me.riseListPro = res.data;
					console.log(me.riseListPro);

					uni.setStorageSync('ttid', id); //把抬头id存入缓存
					var defaultFlag = res.data.defaultFlag;
					uni.setStorageSync('defaultFlag1', defaultFlag);
					console.log('defaultFlag冲冲冲' + JSON.stringify(defaultFlag));
					me.flag = defaultFlag == 1 ? true : false;
				}
			});
		},
		keyword(e) {
			console.log(e);
			var me = this;
			console.log('-------111111111-----');
			console.log(me.riseListPro);
			// var Rise = this;
			var userinfo = uni.getStorageSync('user');
			uni.request({
				url: me.$ServerUrl + '/invoice/api/header/saveInvoiceHeader', //修改发票
				header: {
					'content-type': 'application/json' // 默认值
				},
				data: {
					customer: {
						id: userinfo.id
					},
					id: me.riseListPro.id, //抬头id
					name: this.riseListPro.name,
					taxNo: this.riseListPro.taxNo,
					address: this.riseListPro.address,
					phone: this.riseListPro.phone,
					bankNm: this.riseListPro.bankNm,
					bankAccNo: this.riseListPro.bankAccNo,
					email: this.riseListPro.email,
					defaultFlag: this.riseListPro.defaultFlag
				},
				method: 'POST',
				success(res) {
					console.log(res);
					console.log('-------111111111-----');
					//你在成功之后跳转页面的方式跳回来也可以 你在成功之后跳转页面的方式跳回来也可以
					uni.redirectTo({
						url: '/pages/user/mine/mine-wdtt/mine-wdtt-qy/ttlb',
						success() {
							let page = getCurrentPages().pop(); //跳转页面成功之后
							if (!page) return;
							page.onLoad(); //如果页面存在，则重新刷新页面
						}
					});
				}
			});
		},
		delect(e) {
			var me = this;
			var ttids = uni.getStorageSync('ttid');

			uni.request({
				url: me.$ServerUrl + '/invoice/api/header/delInvoiceHeader', //通过ID获取发票详情
				data: {
					id: ttids
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded' // 默认值JSON格式
				},
				method: 'POST',
				success(res) {
					console.log('删除成功');
					console.log(res);
					uni.redirectTo({
						url: '/pages/user/mine/mine-wdtt/mine-wdtt-qy/ttlb',
						success() {
							let page = getCurrentPages().pop(); //跳转页面成功之后
							if (!page) return;
							page.onLoad(); //如果页面存在，则重新刷新页面
						}
					});
				}
			});
		},
		//默认抬头
		setDefault() {
			var me = this;
			if (me.flag == 1) {
				me.flag = 0;
				me.riseListPro.defaultFlag = 0;
			} else {
				me.flag = 1;
				me.riseListPro.defaultFlag = 1;
			}
			console.log(me.flag);
			console.log(me.riseListPro.defaultFlag);
		}
	}
};
</script>

<style>
page {
	width: 100%;
	height: 100%;
	background-color: #e1e5eb;
}

.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.details-from {
	width: 100%;
	height: 100%;
	padding: 10px;
}

.uni-details-list {
	border: 1px solid #ffffff;
	display: flex;
	background-color: #ffffff;
	align-items: center;
	padding: 10px;
	margin-bottom: 5px;
	border-radius: 10px;
	margin-left: 10px;
	margin-right: 10px;
}

.ad-text {
	margin-left: 10px;
}

.title {
	font-size: 14px;
	width: 65px;
}

.uni-input-01 {
	font-size: 14px;
	margin-left: 10px;
	width: 80%;
	overflow:auto;
}
.uni-input-01 input {
	width: 90%;
}
.uni-input-02 input {
	width: 90%;
}
.uni-input-02 {
	font-size: 14px;
	margin-left: 5px;
	width: 80%;
	overflow:auto;
}

.button-02 {
	margin: 10px;
	color: #ffffff;
	background-color: #ce0000;
}

.button {
	margin: 10px;
	color: #ffffff;
	background-color: #004fa3;
}

.swiths {
	margin-left: 10px;
	transform: scale(0.7);
}
</style>
